package comWorld.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import comWorld.user.UserInfo;
import comWorld.user.UserUrls;

/**
 * Application Lifecycle Listener implementation class SessionAttr
 *
 */
@WebListener
public class SessionAttr implements HttpSessionAttributeListener {

    /**
     * Default constructor. 
     */
    public SessionAttr() {
    }

	/**
     * @see HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)
     */
    public void attributeAdded(HttpSessionBindingEvent event)  { 
		urlAdjust(event);
    }

	/**
     * @see HttpSessionAttributeListener#attributeRemoved(HttpSessionBindingEvent)
     */
    public void attributeRemoved(HttpSessionBindingEvent event)  { 
         
    }

	/**
     * @see HttpSessionAttributeListener#attributeReplaced(HttpSessionBindingEvent)
     */
    public void attributeReplaced(HttpSessionBindingEvent event)  { 
    	urlAdjust(event);
    }
	
    private void urlAdjust(HttpSessionBindingEvent event) {
    	Object obj = event.getValue();
		HttpSession session = event.getSession();
//		if (obj instanceof UserUrls) {
//			UserUrls userUrls = (UserUrls) obj;
//			userUrls.setRootPath(session.getServletContext()
//					.getInitParameter("webRootUrl"));
//		}
    }
}
